package com.boang;

import com.boang.dao.SpuDao;
import com.boang.po.Spu;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/*
  @author: 13813
  @date: 2024/7/23 14:11
*/
public class PageDemo {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        SpuDao spuDao = sqlSession.getMapper(SpuDao.class);

        PageHelper.startPage(1, 3);
        List<Spu> spuList = spuDao.selectSpuPage();
        PageInfo<Spu> pageInfo = new PageInfo<>(spuList);
        System.out.println(pageInfo);

        System.out.println("总条数："+pageInfo.getTotal());
        System.out.println("总页数："+pageInfo.getPages());
        System.out.println("数据：" + pageInfo.getList());
    }
}
